Repository navigation
Use ConsensusFactory when parsing block headers - #1335
Merged
NicolasDorier merged 1 commit intoSep 17, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While reviewing the code to gain familiarity with NBitcoin I noticed what appear to be some oversights in the use of ConsensusFactory.
ConsensusFactory was introduced in 6cb308a but wasn't applied everywhere it could be. Some missed uses were corrected in 5f7c433c.
I found 3 additional missed cases in header parsing:
- BlockHeader.Parse selected a factory but directly constructed a base BlockHeader.
- raw RPC header parsing created the correct header type but did not preserve the network factory during deserialization.
- REST header parsing directly constructed base headers and split the response into fixed 80-byte chunks.
Changes
No public API signatures are changed, and standard Bitcoin header serialization and parsing remain unchanged.
Tests
Added regression coverage using an artificial test-only ConsensusFactory, custom BlockHeader, and custom Block. The custom header includes an extended serialized field and a nested factory-created value, which verifies both concrete type creation and propagation of the factory into deserialization.
Post-rebase test results: